<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="java.util.ArrayList, model.User, model.Course, model.Session, database.DBHandler, servlets.AServlet"%>
<%@page import="java.sql.Connection"%>
<%@include file="/WEB-INF/JSP-Files/headline.jsp" %>
<div id="content">
	<table class="matrix">
	<tr>
		<% if (request.getSession().getAttribute("isAdmin").equals(true)){ %>
			<th>&nbsp;</th>
		<% } %>
		<th>User Name</th><th>Password</th><th>Name</th><th>Family</th><th>Phone</th>
		<th>Courses</th><th>Admin</th>
	</tr>
		<% Connection con = DBHandler.getHandler().getLocalCon();
		ArrayList<User> users = DBHandler.getHandler().getAllUsers(con);
		AServlet.finishTransaction(con, false);
		DBHandler.getHandler().returnLocalCon(con);
		for (User u : users) { %>
			<tr>
				<td><a href="/skiryanoandspuzir/Users?deleteTarget=<%= u.getUserName() %>"><img src="Images/delete_icon.png" alt="delete" /></a></td> 
				<td> <%= u.getUserName() %> </td>
				<td> <%= u.getPassword() %> </td>
				<td> <%= u.getName() %> </td>
				<td> <%= u.getFamily() %> </td>
				<td> <%= u.getPhone() %> </td>
				<td>&nbsp;
					<% if (!u.getCourses().isEmpty()){ %>
						<ul>
						<% for(String course : u.getCourses()){%>
							<li> <%= course %></li>
						<% } %>
						</ul>
					<% } %>
				</td>
				<td> <%= u.isAdmin() ? "Admin" : "&nbsp;" %> </td>
			</tr>
		<% } %>	
	</table>
</div>
</body>
</html>